package com.he.config;

import com.he.constant.RabbitmqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author He
 * @version 1.0
 * @Date 2023/9/9 15:34
 * @Desc Rabbitmq配置类：Direct模式
 */
@Configuration
public class RabbitmqConfig {

    @Bean
    public Queue simpleEmailQueue() {
        return new Queue(RabbitmqConstant.EMAIL_SIMPLE_QUEUE, true, false, false);
    }

    @Bean
    public Queue htmlEmailQueue() {
        return new Queue(RabbitmqConstant.EMAIL_HTML_QUEUE, true, false, false);
    }

    @Bean
    public Queue articleViewQueue() {
        return new Queue(RabbitmqConstant.ARTICLE_VIEW_QUEUE, true, false, false);
    }

    @Bean
    public Queue articleCacheQueue() {
        return new Queue(RabbitmqConstant.ARTICLE_CACHE_QUEUE, true, false, false);
    }

    @Bean
    public DirectExchange redisSyncExchange() {
        return new DirectExchange(RabbitmqConstant.REDIS_SYNC_EXCHANGE, true, false);
    }

    @Bean
    public TopicExchange topicEmailExchange() {
        return new TopicExchange(RabbitmqConstant.EMAIL_EXCHANGE, true, false);
    }

    /**
     * 绑定简单邮件队列
     *
     * @return
     */
    @Bean
    public Binding bindSimpleEmailQueue() {
        return BindingBuilder.bind(simpleEmailQueue()).to(topicEmailExchange()).with(RabbitmqConstant.EMAIL_SIMPLE_KEY);
    }

    /**
     * 绑定html邮件队列
     *
     * @return
     */
    @Bean
    public Binding bindHtmlEmailQueue() {
        return BindingBuilder.bind(htmlEmailQueue()).to(topicEmailExchange()).with(RabbitmqConstant.EMAIL_HTML_KEY);
    }

    /**
     * 绑定文章浏览量队列
     *
     * @return
     */
    @Bean
    public Binding bindArticleViewQueue() {
        return BindingBuilder.bind(articleViewQueue()).to(redisSyncExchange()).with(RabbitmqConstant.ARTICLE_VIEW_KEY);
    }


}
